/// <reference types="node" />
import { defineConfig, type PluginOption } from 'vite';
import vue from '@vitejs/plugin-vue';
import { readFileSync } from 'fs';
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

export default defineConfig({
  plugins: [vue() as PluginOption],
  server: {
    port: parseInt(process.env.VITE_DEV_SERVER_PORT || '5173'),
    host: process.env.VITE_DEV_SERVER_HOST || 'localhost',
    https: {
      key: readFileSync(resolve(__dirname, '../certs/smartinput.key')),
      cert: readFileSync(resolve(__dirname, '../certs/smartinput.crt')),
    },
    proxy: {
      '/api': {
        target: process.env.VITE_API_BASE_URL || 'https://localhost:8443',
        changeOrigin: true,
        secure: false, // 允许自签名证书
      },
    },
  },
});